//
//  PredictionManager.m
//  Pennyworth
//
//  Created by Chris Karr on 1/11/08.
//  Copyright 2008 Chris J. Karr. All rights reserved.
//

#import "PredictionManager.h"
#import "AnalyticsLogger.h"

@implementation PredictionManager

- (void) setMenu
{
	NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

	if ([defaults boolForKey:PREDICTIONS_ACTIVE])
		[menuItem setTitle:@"Pause Predictions"];
	else
		[menuItem setTitle:@"Resume Predictions"];
}

- (void) awakeFromNib
{
	NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
	
	if ([defaults valueForKey:PREDICTIONS_ACTIVE] == nil)
		[defaults setBool:YES forKey:PREDICTIONS_ACTIVE];

	[self setMenu];
}

- (IBAction) togglePredictions:(id) sender
{
	NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

	BOOL active = [defaults boolForKey:PREDICTIONS_ACTIVE];
	
	[defaults setBool:!active forKey:PREDICTIONS_ACTIVE];

	if (!active)
	{
		NSDictionary * postObject = [NSDictionary dictionaryWithObjectsAndKeys:@"Disabled Predictions", ANALYTIC_NAME, @"", ANALYTIC_VALUE, nil];
		[[NSNotificationCenter defaultCenter] postNotificationName:ANALYTIC_EVENT object:postObject];
	}
	else
	{
		NSDictionary * postObject = [NSDictionary dictionaryWithObjectsAndKeys:@"Enabled Predictions", ANALYTIC_NAME, @"", ANALYTIC_VALUE, nil];
		[[NSNotificationCenter defaultCenter] postNotificationName:ANALYTIC_EVENT object:postObject];
	}

	[self setMenu];
}

- (IBAction) nilAction:(id) sender
{

}

@end
